package edu.washington.ling.syntric.struct.error;

import java.util.ArrayList;

import edu.washington.ling.syntric.util.Utils;


public class UnreadableRepresentationException extends Exception {

	private static final long serialVersionUID = -1745309038672323928L;
	private ArrayList<String> subErrors;
	
	public UnreadableRepresentationException(String message) {
		super(message);
		subErrors = null;
	}
	public UnreadableRepresentationException(String message, ArrayList<String> subErrors) {
		super(message);
		this.subErrors = subErrors;
	}
	public boolean hasSubErrors() {
		return (subErrors != null);
	}
	public String getSubErrorStr() {
		ArrayList<String> tabSubErrors = new ArrayList<String>();
		for (String subError: subErrors) {
			subError = "\t" + subError;
			subError = subError.replaceAll("\n", "\n\t");
			tabSubErrors.add(subError);
		}
		return Utils.join(tabSubErrors, "\n\n");
	}
	@Override
	public String getMessage() {
		String message = super.getMessage();
		if (this.hasSubErrors()) {
			return String.format("%s\n%s", message, getSubErrorStr());
		}
		else { return message; }
	}
	
}
